<%@page import="com.core.util.DspUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DSP</title>
<%@include file="../common/link.jsp"%>
<script src="javascript?type=selectTags"></script>
<script src="javascript?type=Com"></script>
<script>
	var config = {
		url : "employees"
	}
	var colModel = [{
		title : ' 公司',
		field : 'company',
		width : 90,
		algin : 'left',
		formatter : function(cell, row , index) {
			var val = '';
			for ( var i = 0; i < Com.length; i++) {
				if (cell == Com[i].id) {
					val = Com[i].value;
					break;
				}
			}
			return val;
		}
	}, {
		title : '姓名',
		field : 'empname',
		width : 60,
		//sortable : true,
		align : 'left',
		formatter : function(cell, row , index) {
			return "<a href='###' onclick='javascript:DSP.update("+row.id+");' >" + cell + "</a>";
		},
		link : true
	},{
		title : '<font color="blue">公积金状态</font>',
		field : 'isProvident',
		width : 50,
		align : 'center',
		formatter : function(cell , row ,index){
			var color = '';
			if(cell == '0'){
				color='blue';
			} else if (cell == 2){
				color = 'red';
			} 
			return '<font color="'+color+'">'+selectTags["insure_"+cell]+'</font>';
		}
	},{
		title : '公积金基数',
		field : 'providentBase',
		width : 80,
		align : 'center',
		formatter:function(cell , row ,index){
			if(row.isProvident == '1') {//已加保
				return cell;
			} 
			return ''; //未加保，就先不显示基数了，虽然默认存将公司的基数存入
		}
	}, {
		title : '身份证',
		field : 'empidn',
		width : 110,
		//sortable : true,
		align : 'left'
	}, {
		title : '性别',
		field : 'sex',
		width : 30,
		//sortable : true,
		align : 'left',
		formatter : function(cell, row , index) {
			return selectTags["sex_" + cell];
		}
	},{
		title : '户口性质',
		field : 'hukou',
		width : 60,
		align : 'center',
		formatter : function(cell, row , index) {
			return selectTags["hukou_" + cell];
		}
	} ];
	var btnModel = [
			{
				id : 'btnAdd',
				text : '加保',
				iconCls : 'icon-add',
				handler : function() {
					signUpdate();
				}
			},'-',{
				id : 'btnRemove',
				text : '退保',
				iconCls : 'icon-remove',
				handler : function() {
					signRemove();
				}
			}
	];
	function signRemove(){
		var row = $("#xDataGrid").datagrid("getSelected");
		if(row){
			DSP.Server(config.url+"_remove?insure=2&isProvident=1",{id:row.id},function(json){
				if(json.success){
					msgShow("系统提示","退保成功","info");
					$("#xDataGrid").datagrid('clearSelections');
					DSP.grid.query();
				} else {
					msgShow("系统提示", json.msg, "warning");
				}
			}, DSP.contentType);
		} else {
			msgShow("系统提示", "请选择要退保的员工", "warning");
		}
	}
	function signUpdate(){
		var row = $("#xDataGrid").datagrid('getSelected');
		if(row){
			DSP.update(row.id);
		} else {
			msgShow("系统提示", "请选择要加保的员工", "warning");
		}
	}
	
	function sign(){
		var form = $("#form1").serializeObject();
		DSP.Server(config.url+'_one?insure=2' , form ,function(json){
			if (json.success) {
				$("#dialog_div").window("close");
				DSP.grid.query(); // 重新加载数据
			} else {
				msgShow("系统提示", json.msg, "warning");
			}
		} , DSP.contentType);
	}
	
</script>
</head>
<body>
<form id="qForm">
		<table width="60%" cellspacing="3" cellpadding="3"
			bordercolor="#DEDEDC" border="0" id="q-form" >
			<tr>
				<th width="15%" class="td_left" valign="middle">公司:</th>
				<td width="20%"><select id="q_company" name="q_company"></select>
				<script>
							var options = "<option value=''>请选择公司</option>";
							$.each(Com, function(i, d) {
								if(d.id != '')
									options += "<option value="+d.id+">" + d.value + "</option>";
							});
							$("#q_company").empty().append(options);
				</script>
				</td>
				<th width="15%" class="td_left" valign="middle">姓名:</th>
				<td width="20%"><input type="text" name="q_empname" id="q_empname" />
				</td>
			</tr>
			<tr>
				<th width="15%" class="td_left" valign="middle">代理方式:</th>
				<td><input type="text" name="q_cMethod" id="q_cMethod" />
				</td>
				<th class="td_left" valign="middle">户口性质:</th>
				<td><dsp:selectTag htmlId="q_hukou" tagId="hukou" isAll="true"/>
				</td>
			</tr>
			<tr>
				<th width="10%" class="td_left" valign="middle">公积金:</th>
				<td><dsp:selectTag htmlId="q_isProvident" tagId="insure" isAll="" htmlValue="0"/>
				</td>
			</tr>
		</table>
		</form>
	<div id="dialog_div" class="easyui-window" title="公积金加保信息"
		collapsible="false" minimizable="false" maximizable="false" icon="icon-save"
		style="left: 250px; top: 100px; padding: 5px; background: #fafafa;">
		<div class="easyui-layout" fit="true">
			<div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
				<form action="" id="form1" name="form1">
					<input type="hidden" name="id" id="id" value="" />
					<input type="hidden" name="isProvident" id="isProvident" value=""/>
					<table width="100%" cellspacing="3" cellpadding="3" bordercolor="#DEDEDC" border="0" id="id-form">
					<tr>
						<th class="td_left" valign="middle" style="width:40%;"><span style="color: #FF0000">*</span>员工公积金基数:</th>
 						<td><input type="text" name="providentBase" id="providentBase" size="10"
								jval="{valid:function(val){ if (val.length == 0){  return '不能为空'; } else {  return ''; }}}" />
						</td>
					</tr>
					</table>
				</form>
			</div>
			<div region="south" border="false"
				style="text-align: right; height: 30px; line-height: 30px;">
				<a id="btnEp" class="easyui-linkbutton" icon="icon-ok"
					href="javascript:sign();"> 确定</a> <a id="btnCancel"
					class="easyui-linkbutton" icon="icon-cancel"
					href="javascript:DSP.close();">取消</a>
			</div>
		</div>
	</div>
	<table id="xDataGrid"></table>
	<script type="text/javascript">
	$(function() {
		DSP.open(false,200 , 300 ,"");
		DSP.grid1(colModel, btnModel, {q_isProvident:0} , "公积金加保信息");
		
		//监听查询输入框事件
		$("#q-form input").keyup(function(event){
			var e = event || window.event; //浏览器兼容
			if(e.keyCode == 13){ 
				 DSP.grid.query();
			}
		});
		
		//监听查询输入框事件
		$("#q-form select").change(function(){
			DSP.grid.query();
		});
	});
		
	function update(data) {
		$("#id").attr("value",data.id);
		$("#isProvident").attr("value",data.isProvident);
		$("#providentBase").attr("value", data.insureBase);
	}
	</script>
</body>
</html>
